import * as vscode from 'vscode';

export abstract class BaseTreeItem extends vscode.TreeItem {
    constructor(
        public label: any,
        public readonly collapsibleState: vscode.TreeItemCollapsibleState
    ) {
        super(label, collapsibleState);
    }

    protected setIcon(icon: string | vscode.ThemeIcon) {
        this.iconPath = icon;
    }

    protected setDescription(description: string) {
        this.description = description;
    }

    protected setTooltip(tooltip: string) {
        this.tooltip = tooltip;
    }

    protected setContextValue(value: string) {
        this.contextValue = value;
    }

    protected setHighlight(color: string) {
        if (typeof this.label === 'string') {
            this.label = {
                label: this.label,
                highlights: [[0, this.label.length]]
            };
        }

        if (this.label && typeof this.label === 'object') {
            (this.label as any).color = new vscode.ThemeColor(color);
        }
    }
}
